// pages/person_attestation/person_attestation.js
const app = getApp(), core = require('../../utils/core'), WeValidator = require('../../utils/we-validator');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    status: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOpenerEventChannel().on('infoTransfer', data => {
      this.setData({
        info: data.info,
        status: data.status,
      });
    });
  },
  onUnload() {
    this.getOpenerEventChannel().emit('infoTransfer',this.data);
  },
  // 提交
  bindSubmit(event) {
    if(![0,3].includes(parseInt(this.data.audit_status)))
      return;
    let data = event.detail.value;
    let validator = new WeValidator({
      rules: {
        personal_realname: {required: true},
        personal_identity_no: {required: true, idcard: true},
      },
      messages: {
        personal_realname: {required: '请填写姓名'},
        personal_identity_no: {required: '请填写身份证号'},
      }
    });
    if(!validator.checkData(data)) {
      return;
    }
    core.post({
      url: 'enterprise/personal_audit', data: data,
      success: ret => {
        this.data.status = ret.data.audit_status;
        this.data.info.personal_realname = ret.data.audit_info.personal_realname;
        this.data.info.personal_identity_no = ret.data.audit_info.personal_identity_no;
        this.setData(this.data);
      }
    })
  }

});
